Home:ALL Converter>Doctrine where Query- Logical order - Where(condition1 and [condition2 or condition3])

Doctrine where Query- Logical order - Where(condition1 and [condition2 or condition3])

Ask Time:2017-07-12T23:49:46         Author:basti500

Json Formatter

I'm currently writing a Shopware Plugin. Shopware uses Doctrine for Database operations.

I would like to write a doctrine statement like this:

Where(condition1 and [condition2 or condition3])

See my comment in the code.

$builder = Shopware()->Models()->createQueryBuilder();
$builder->select([
        'orders',
        'details',
        'customer',
        'shipping',
        'billing'
]);
$builder->from('Shopware\Models\Order\Order', 'orders');
$builder->leftJoin('orders.details', 'details')
        ->leftJoin('orders.customer', 'customer')
        ->leftJoin('orders.shipping', 'shipping')
        ->leftJoin('orders.billing', 'billing');


//--> Here I would like to write an or statement.
// So that i get all the orders by
// where(customers.email = email) and [(shipping.zipCode = zip) or (billing.zipcode = zip)]
$builder->where('customer.email = :email');
$builder->andWhere('(shipping.zipCode = :zipCode) orWhere (billing.zipCode = :zipCode)');

$builder->setParameter('email', $email);
$builder->setParameter('zipCode', $zip);
$builder->orderBy('orders.id', 'DESC');

$order = $builder->getQuery()->getResult($this->getResultMode());

Author:basti500,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45062409/doctrine-where-query-logical-order-wherecondition1-and-condition2-or-condit
yy